package com.kxf.androidtestdemo.adapter;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kxf.androidtestdemo.R;
import com.kxf.androidtestdemo.view.MyViewHolder;
import com.kxf.utils.MaxSizeHashMap;

/**
 * @ProjectName: AndroidTestDemo
 * @Package: com.kxf.androidtestdemo.adapter
 * @ClassName: MyListAdapterHolder
 * @Description: java类作用描述
 * @Author: kuangxuefeng
 * @qq: 1024883177
 * @CreateDate: 2020/6/16 17:02
 */
public class MyListAdapterHolder extends BaseAdapter {
    private int len = 50;
    private MaxSizeHashMap<Integer, View> maxSizeHashMap = new MaxSizeHashMap(10);

    @Override
    public int getCount() {
        return len;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder vh =null;
        if(convertView==null){
            vh = new MyViewHolder();
            convertView = View.inflate(parent.getContext(), R.layout.list_item, null);
            Log.d("MyListAdapterHolder", position + " convertView创建 " + convertView);
            vh.setTitle((TextView) convertView.findViewById(R.id.title));
            vh.setTime((TextView) convertView.findViewById(R.id.time));

            convertView.setTag(vh);
        }else{
            Log.d("MyListAdapterHolder", position + " convertView复用 " + convertView);
            vh = (MyViewHolder) convertView.getTag();
        }

        vh.getTitle().setText("当前item:" + position);
        vh.getTime().setText("time:" + System.currentTimeMillis());

        return convertView;
    }
}
